//
//  LLViewModel.m
//  lrlzapp
//
//  Created by dl on 16/2/22.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLViewModel.h"

@interface LLViewModel ()

@property(nonatomic, strong, readwrite) LLNavigationControllerStack *navService;
@property(nonatomic, copy, readwrite) NSDictionary *params;
@property(nonatomic, strong, readwrite) RACSubject *errors;
@property(nonatomic, strong, readwrite) RACSubject *willDisappearSignal;

@end

@implementation LLViewModel

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    LLViewModel *viewModel = [super allocWithZone:zone];

    @weakify(viewModel)
    [[viewModel
            rac_signalForSelector:@selector(initWithParams:)]
            subscribeNext:^(id x) {
                @strongify(viewModel)
                [viewModel initialize];
            }];

    [[viewModel
            rac_signalForSelector:@selector(init)]
            subscribeNext:^(id _) {
                @strongify(viewModel)
                [viewModel initialize];
            }];

    return viewModel;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        self.navService = [LLNavigationControllerStack sharedInstance];
    }
    return self;
}

- (instancetype)initWithParams:(NSDictionary *)params {
    self = [super init];
    if (self) {
        self.navService = [LLNavigationControllerStack sharedInstance];
        self.params = params;
        self.title = params[@"title"];
    }
    return self;
}

- (RACSubject *)errors {
    if (!_errors) _errors = [RACSubject subject];
    return _errors;
}

- (RACSubject *)willDisappearSignal {
    if (!_willDisappearSignal) _willDisappearSignal = [RACSubject subject];
    return _willDisappearSignal;
}

- (void)initialize {
    self.shouldFetchLocalDataOnViewModelInitialize = YES;
    self.shouldRequestRemoteDataOnViewDidLoad = YES;
}


@end
